package jjn.kamacoder.case20;

import java.util.Scanner;

/**
 * @author Jjn
 * @since 2023-08-31 17:03
 */
public class Main {
    
    static class ListNode {
        int val;
        ListNode next;
    }
    
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            int count = scanner.nextInt();
            if (count == 0) {
                System.out.println("list is empty");
                break;
            }
            ListNode dummy = new ListNode();
            ListNode head = dummy;
            for (int i = 0; i < count; i++) {
                ListNode node = new ListNode();
                node.val = scanner.nextInt();
                head.next = node;
                head = head.next;
            }
            ListNode cur = dummy.next;
            while (cur != null) {
                System.out.print(cur.val);
                System.out.print(" ");
                cur = cur.next;
            }
            System.out.println();
            cur = dummy.next;
            while (cur != null && cur.next != null) {
                if (cur.val == cur.next.val) {
                    cur.next = cur.next.next;
                } else {
                    cur = cur.next;
                }
            }
            cur = dummy.next;
            while (cur != null) {
                System.out.print(cur.val);
                System.out.print(" ");
                cur = cur.next;
            }
            System.out.println();
        }
    }
}
